home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
FANGS__
/
OFFSETLI.C
< prev
next >
Wrap
Text File
|
1990-05-29
|
5KB
|
206 lines
/* ⌐ 1990 Patrick Doane. */
#include <OffsetList.h>
#include <oops.h>
#include <Utilities.h>
extern GrafPtr scratchPort;
void OffsetList::IOffsetList(WindowPtr theWindow,Rect *theBounds,
Boolean hasVert,short theRows,short theRowWidth,ShortFunc theCompareProc,
VoidFunc theDoubleProc,VoidFunc theChangeFunc)
{
Rect theRect;
SelectList::ISelectList(theWindow,theBounds,hasVert,theRows,
theRowWidth,theCompareProc,theDoubleProc);
theRect.left = theBounds->left - 35;
theRect.right = theBounds->left - 1;
theRect.top = theBounds->top - 1;
theRect.bottom = theRect.top + 16;
itsOffsetNum = new(OffsetNum);
if (theChangeFunc)
itsOffsetNum->IOffsetNum(theWindow,&theRect,0x8000,0x8000,
0x8000,0,theChangeFunc,0);
else
itsOffsetNum->IOffsetNum(theWindow,&theRect,0x8000,0x8000,
0x8000,0,ChangeList,0);
itsOffsetNum->refCon = (long)this;
}
void OffsetList::Dispose(void)
{
inherited::Dispose();
}
void OffsetList::SetSelection(short theSelection)
{
InvertRow(currentSelection);
currentSelection = theSelection;
InvertRow(currentSelection);
MoveArrow();
}
void OffsetList::Scroll(short hDelta,short vDelta,Boolean redraw)
{
short hPixels;
short vPixels;
Rect theRect;
RgnHandle invalRgn;
invalRgn = NewRgn();
hPixels = hDelta * hScale;
vPixels = vDelta * vScale;
if (redraw)
{ theRect = bounds;
ScrollRect(&theRect,-hPixels,-vPixels,invalRgn);
InvalRgn(invalRgn);
}
position.h += hDelta;
position.v += vDelta;
MoveArrow();
if (redraw)
{ BeginUpdate(thePort);
Update();
EndUpdate(thePort);
}
}
void OffsetList::DrawRow(short rowNum)
{
long rowSize;
Ptr rowPtr;
register Rect theBounds;
register OffsetListRec theRecord;
Str255 theString;
short vOffset;
if (ValidRow(rowNum))
{ theBounds = bounds;
vOffset = bounds.top + rowHeight * (rowNum - position.v) - vIndent;
MoveTo(bounds.left + hIndent,vOffset);
rowPtr = GetRowOffset(rowNum);
theRecord = *(OffsetListRec *)rowPtr;
DrawString(theRecord.title);
NumToString(theRecord.currentValue,theString);
MoveTo(bounds.left + hIndent+120,vOffset);
DrawString(theString);
}
}
void OffsetList::DoClick(EventRecord *theEvent)
{
Rect theBounds,theRect,arrowBounds;
short lastItem;
Point mouseLoc;
Boolean newState;
theBounds = bounds;
lastItem = currentSelection;
currentSelection = (theEvent->where.v - theBounds.top +
(position.v * rowHeight)) / rowHeight + 1;
if (ValidRow(currentSelection))
{ if (currentSelection == clickRow && (theEvent->when - clickTime)
< GetDblTime())
(*doubleProc)(this);
else
{ InvertRow(lastItem);
InvertRow(currentSelection);
lastItem = currentSelection;
MoveArrow();
}
}
else
{ InvertRow(currentSelection);
currentSelection = 0;
}
clickTime = theEvent->when;
clickRow = currentSelection;
while (TrackMouse(&mouseLoc,&theBounds,&newState,0))
{ currentSelection = (mouseLoc.v - theBounds.top +
(position.v * rowHeight)) / rowHeight + 1;
if (ValidRow(currentSelection))
{ if (currentSelection != lastItem)
{ InvertRow(lastItem);
InvertRow(currentSelection);
lastItem = currentSelection;
MoveArrow();
}
}
else
{ InvertRow(lastItem);
currentSelection = 0;
lastItem = currentSelection;
itsOffsetNum->Hide();
arrowBounds = itsOffsetNum->bounds;
EraseRect(&arrowBounds);
}
}
clickTime = theEvent->when;
clickRow = currentSelection;
}
void OffsetList::MoveArrow(void)
{
Rect arrowBounds;
Rect theRect;
if (currentSelection >= position.v + 1 && currentSelection <= position.v + visRows)
{ arrowBounds = itsOffsetNum->bounds;
theRect.left = bounds.left - 35;
theRect.right = bounds.left - 1;
theRect.top = bounds.top - 1 +
(currentSelection - 1 - position.v) * rowHeight;
theRect.bottom = theRect.top + 16;
itsOffsetNum->SetBounds(&theRect);
EraseRect(&arrowBounds);
itsOffsetNum->Show();
itsOffsetNum->Update();
}
else
{ itsOffsetNum->Hide();
arrowBounds = itsOffsetNum->arrowBounds;
EraseRect(&arrowBounds);
}
}
void ChangeList(register OffsetNum *theOffsetNum,short theParam)
{
register OffsetList *theList;
register OffsetListRec *theRecord;
short currentRow;
GrafPtr savePort;
Rect theRect;
theList = (OffsetList *)theOffsetNum->refCon;
currentRow = theList->currentSelection;
theRecord = (OffsetListRec *)theList->GetRowOffset(currentRow);
switch (theParam)
{ case DoIncrease:
theRecord->currentValue += theRecord->stepValue;
theRecord->offset += theRecord->stepValue;
break;
case DoDecrease:
theRecord->currentValue -= theRecord->stepValue;
theRecord->offset -= theRecord->stepValue;
break;
}
GetPort(&savePort);
SetPort(scratchPort);
theRect = theList->bounds;
theRect.top = theList->rowHeight * (currentRow - 1 -
theList->position.v) + theList->bounds.top;
theRect.bottom = theRect.top + theList->rowHeight;
EraseRect(&theRect);
theList->DrawRow(currentRow);
theList->InvertRow(currentRow);
SetPort(savePort);
CopyBits(&scratchPort->portBits,&thePort->portBits,&theRect,&theRect,
srcCopy,0L);
}